import Mock from 'mockjs2';
import { builder, getBody } from '../util';

const username = ['1658'];
const password = ['c3VuMTk4NzAyMTY='];

const login = options => {
  const body = getBody(options);
  console.log('mock: body', body);
  if (!username.includes(body.userId) || !password.includes(body.password)) {
    return builder(false, {}, '账户或密码错误', null);
  }

  return builder(
    true,
    {
      "deptCode": "xx",
      "deptName": "XXX",
      "userName": "资讯部",
      "userId": "1658",
      "token": '123456789'
    },
    "",
    null
  );
};

const getpermissionlist = options => {
  const body = getBody(options);
  console.log('mock: body', body);
  if (body.userId) {
    return builder(false, {}, '用户工号不能为空', null);
  }

  return builder(
    true,
    {
      "auth": [
        {
          "checkValue": "",
          "enable": "Y",
          "hint": "清空预约",
          "iconName": "setting",
          "id": "1328509386670211072",
          "insertTime": 1605576294000,
          "insertUser": "MSADMIN",
          "kind": "1",
          "name": "清空预约",
          "pid": "69",
          "sort": 1,
          "tailInfos": {},
          "updateTime": 1605576427000,
          "updateUser": "MSADMIN",
          "version": 0,
          "webIsAlwaysShow": 0,
          "webIsHidden": 0,
          "webIsLeaf": 1,
          "webIsRoute": 0,
          "webKeepAlive": 1,
          "webPerms": "book:SundryBook:newbook",
          "webResourceType": 2
        },
      ],
      "action": "itOperations:comColumnConfig:remove",
      "describe": "删除权限",
      "menu": [
        {
          "path": "/SearchManager",
          "component": "layouts/RouteView",
          "route": "0",
          "children": [
            {
              "path": "/search/YardEfficiency",
              "component": "search/YardEfficiency",
              "route": "0",
              "meta": {
                "keepAlive": true,
                "internalOrExternal": false,
                "icon": "setting",
                "title": "堆场业务量查询",
                "url": "/search/YardEfficiency"
              },
              "name": "search-YardEfficiency",
              "id": "1376396466503360512"
            },
          ],
          "meta": {
            "keepAlive": true,
            "internalOrExternal": false,
            "icon": "search",
            "title": "业务查询",
            "url": "/SearchManager"
          },
          "name": "SearchManager",
          "id": "78"
        },
        {
          "path": "/itOperations",
          "component": "layouts/RouteView",
          "route": "0",
          "children": [
            {
              "path": "/itOperations/oraclelockinfo",
              "component": "itOperations/OracleLockInfo",
              "route": "0",
              "meta": {
                "keepAlive": true,
                "internalOrExternal": false,
                "icon": "lock",
                "title": "ORACLE锁信息查询",
                "url": "/itOperations/oraclelockinfo"
              },
              "name": "itOperations-oraclelockinfo",
              "id": "1716368440283394048"
            },
            {
              "path": "/itOperations/operations",
              "component": "itOperations/operations",
              "route": "0",
              "meta": {
                "keepAlive": true,
                "internalOrExternal": false,
                "icon": "solution",
                "title": "运维专用",
                "url": "/itOperations/operations"
              },
              "name": "itOperations-operations",
              "id": "1462643982147854336"
            },
          ],
          "meta": {
            "keepAlive": true,
            "internalOrExternal": false,
            "icon": "api",
            "title": "IT运维",
            "url": "/itOperations"
          },
          "name": "itOperations",
          "id": "1462642291809771520",
          "alwaysShow": true
        }
      ],
      "type": 2
    },
    "",
    null
  );
};

const logout = () => {
  return builder(true, {}, null, '[测试接口] 注销成功');
};

Mock.mock(/\/login/, 'post', login);
Mock.mock(/\/getpermissionlist/, 'post', getpermissionlist);
Mock.mock(/\/logout/, 'post', logout);
